import { VEMesh, VEVertex } from "../core/";

export function addVertex(
  ve_mesh: VEMesh,
  position: BABYLON.Vector3,
  normal: BABYLON.Vector3,
  checkDuplicates = false,
  tolerance = 1e-10) {

  // 剔除冗余点
  if (checkDuplicates) {
    for (const vertex of ve_mesh.vertices) {
      if (vertex.matchesPosition(position, tolerance)) {
        // console.log('冗余点在此！');
        // console.warn(vertex);
        // console.error(position);
        // console.error(normal);
        return vertex;
      }
    }
  }

  const v = new VEVertex();
  v.position.copyFrom(position);
  v.normal.copyFrom(normal);
  ve_mesh.vertices.push(v);
  return v;
}